<!--
描述：学校管理-院系专业管理
开发人：zhaohang
开发日期：2019年10月29日
-->

<template lang="pug">
  div.active
    keep-alive
      kalix-tree-grid(
      bizKey="department"
      v-bind:columns='columns'
      v-bind:targetURL="targetURL"
      title="院系专业列表"
      v-bind:btnList="btnList"
      v-bind:bizDialog="bizDialog"
      v-bind:formModel="formModel"
      v-bind:dialogOptions="dialogOptions"
      v-on:selectedRow="selectedRow"
      v-bind:isSearchAfterHandle="true"
      v-on:handleAfterSearch="handleAfterSearch"
      v-bind:isLimitLayer="false"
      v-bind:toolbarBtnList="toolBarBtnList"
      v-bind:buttonPermissionPrefix="buttonPermissionPrefix")
</template>

<script type="text/ecmascript-6">
  import FormModel from './model'
  import {departmentBtnList} from './config'
  import {departmentURL, departmentBtnPermissionPrefix} from '../../config.toml'

  export default {
    name: 'kalix-mplive-departmentspecialty',
    data() {
      return {
        btnList: departmentBtnList,
        toolBarBtnList: [
          {id: 'add', isShow: true, title: '添加', isPermission: true}
        ],
        targetURL: departmentURL + '/getSchool',
        formModel: Object.assign({}, FormModel),
        columns: [{
          type: 'hidden',
          key: 'id',
          width: '0'
        }, {
          type: 'hidden',
          key: 'parentId',
          width: '0'
        }, {
          title: '名称',
          key: 'name',
          width: '200'
        }, {
          title: '创建人',
          key: 'createBy',
          width: '350'
        }, {
          title: '创建日期',
          key: 'creationDate',
          width: '350'
        }, {
          title: '操作',
          type: 'action',
          actions: [{
            type: 'edit',
            text: '编辑',
            icon: 'el-icon-edit'
          }, {
            type: 'delDepartment',
            text: '删除',
            icon: 'el-icon-delete'
          }],
          width: '20'
        }],
        bizDialog: [
          {id: 'edit', dialog: 'SchoolDepartmentEdit'},
          {id: 'add', dialog: 'SchoolDepartmentAdd'}],
        dialogOptions: {},
        buttonPermissionPrefix: departmentBtnPermissionPrefix
      }
    },
    methods: {
      selectedRow(row) {
        if (row) {
          this.dialogOptions = {
            parentId: row.id,
            // 选中以后departmentName 为当前选中行的值
            departmentName: row.name
          }
        }
      },
      handleAfterSearch(tableData) {
        if (tableData && tableData.length) {
          this.dialogOptions = {
            parentId: tableData[0].parentId,
            // 未被选中时orgName 为父节点名
            departmentName: tableData[0].parentName
          }
        }
      }
    }
  }
</script>

<style scoped lang="stylus">

</style>

<style lang="stylus">
  .active .table-bordered > thead > tr > th
    color #3c9cc1!important
</style>
